Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

store/copr: set concurrency to partition number for limit statements #41500

Merged
merged 4 commits into from
Feb 17, 2023

Conversation

you06
Copy link
Contributor

@you06 you06 commented Feb 16, 2023

What problem does this PR solve?

Issue Number: ref #41480

Problem Summary:

The distsql concurrency of limit statement is set to 1 before, but with partitioned table, it may affect performance, see the case in #41480.

MySQL [test]> CREATE TABLE t(id int PRIMARY KEY, val int)
    -> PARTITION BY RANGE (id)
    -> (PARTITION p1 VALUES LESS THAN (100),
    ->  PARTITION p2 VALUES LESS THAN (200),
    ->  PARTITION p3 VALUES LESS THAN (300),
    ->  PARTITION p4 VALUES LESS THAN (400),
    ->  PARTITION p5 VALUES LESS THAN (500),
    ->  PARTITION p6 VALUES LESS THAN (600),
    ->  PARTITION p7 VALUES LESS THAN (700),
    ->  PARTITION p8 VALUES LESS THAN (800),
    ->  PARTITION p9 VALUES LESS THAN (900),
    ->  PARTITION p10 VALUES LESS THAN (1000),
    ->  PARTITION p11 VALUES LESS THAN (1100),
    ->  PARTITION p12 VALUES LESS THAN (1200),
    ->  PARTITION p13 VALUES LESS THAN (1300),
    ->  PARTITION p14 VALUES LESS THAN (1400),
    ->  PARTITION p15 VALUES LESS THAN (1500));
Query OK, 0 rows affected (0.134 sec)

MySQL [test]> 
MySQL [test]> INSERT INTO t VALUES(50, 50), (150, 150), (250, 250);
Query OK, 3 rows affected (0.004 sec)
Records: 3  Duplicates: 0  Warnings: 0

MySQL [test]> ANALYZE TABLE t;
Query OK, 0 rows affected, 30 warnings (1.414 sec)

## Before this PR
MySQL [test]> EXPLAIN ANALYZE SELECT * FROM t ORDER BY id ASC LIMIT 1;
+----------------------------+---------+---------+-----------+---------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------+-----------+------+
| id                         | estRows | actRows | task      | access object | execution info                                                                                                                                                                                                                                   | operator info                | memory    | disk |
+----------------------------+---------+---------+-----------+---------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------+-----------+------+
| TopN_7                     | 1.00    | 1       | root      |               | time:10.6ms, loops:2                                                                                                                                                                                                                             | test.t.id, offset:0, count:1 | 280 Bytes | N/A  |
| └─TableReader_14           | 1.00    | 3       | root      | partition:all | time:10.6ms, loops:3, cop_task: {num: 18, max: 869.7µs, min: 423.9µs, avg: 536.6µs, p95: 869.7µs, max_proc_keys: 1, p95_proc_keys: 1, rpc_num: 18, rpc_time: 9.25ms, copr_cache_hit_ratio: 0.00, distsql_concurrency: 1}                         | data:Limit_13                | 319 Bytes | N/A  |
|   └─Limit_13               | 1.00    | 3       | cop[tikv] |               | tikv_task:{proc max:1ms, min:0s, avg: 55.6µs, p80:0s, p95:1ms, iters:18, tasks:18}, scan_detail: {total_process_keys: 3, total_process_keys_size: 113, total_keys: 21, get_snapshot_time: 495.3µs, rocksdb: {key_skipped_count: 3, block: {}}}   | offset:0, count:1            | N/A       | N/A  |
|     └─TableFullScan_12     | 3.00    | 3       | cop[tikv] | table:t       | tikv_task:{proc max:1ms, min:0s, avg: 55.6µs, p80:0s, p95:1ms, iters:18, tasks:18}                                                                                                                                                               | keep order:false             | N/A       | N/A  |
+----------------------------+---------+---------+-----------+---------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------+-----------+------+
4 rows in set (0.012 sec)

## After this PR
MySQL [test]> EXPLAIN ANALYZE SELECT * FROM t ORDER BY id ASC LIMIT 1;
+----------------------------+---------+---------+-----------+---------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------+-----------+------+
| id                         | estRows | actRows | task      | access object | execution info                                                                                                                                                                                                                            | operator info                | memory    | disk |
+----------------------------+---------+---------+-----------+---------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------+-----------+------+
| TopN_7                     | 1.00    | 1       | root      |               | time:1.47ms, loops:2                                                                                                                                                                                                                      | test.t.id, offset:0, count:1 | 280 Bytes | N/A  |
| └─TableReader_14           | 1.00    | 3       | root      | partition:all | time:1.43ms, loops:3, cop_task: {num: 15, max: 1.11ms, min: 891.7µs, avg: 982.6µs, p95: 1.11ms, max_proc_keys: 1, p95_proc_keys: 1, rpc_num: 15, rpc_time: 13.9ms, copr_cache_hit_ratio: 0.00, distsql_concurrency: 15}                   | data:Limit_13                | 2.92 KB   | N/A  |
|   └─Limit_13               | 1.00    | 3       | cop[tikv] |               | tikv_task:{proc max:0s, min:0s, avg: 0s, p80:0s, p95:0s, iters:15, tasks:15}, scan_detail: {total_process_keys: 3, total_process_keys_size: 113, total_keys: 18, get_snapshot_time: 654.6µs, rocksdb: {key_skipped_count: 3, block: {}}}  | offset:0, count:1            | N/A       | N/A  |
|     └─TableFullScan_12     | 3.00    | 3       | cop[tikv] | table:t       | tikv_task:{proc max:0s, min:0s, avg: 0s, p80:0s, p95:0s, iters:15, tasks:15}                                                                                                                                                              | keep order:true              | N/A       | N/A  |
+----------------------------+---------+---------+-----------+---------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------------------------+-----------+------+
4 rows in set (0.003 sec)

What is changed and how it works?

Set the concurrency to the number of partitions, with a upper limit of distsql concurrency(default to 15).

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

store/copr: set concurrency to partition number for limit statement to reduce latency.

@you06 you06 requested a review from winoros February 16, 2023 08:34
@ti-chi-bot
Copy link
Member

ti-chi-bot commented Feb 16, 2023

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • jackysp
  • winoros

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added do-not-merge/cherry-pick-not-approved release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Feb 16, 2023
@you06
Copy link
Contributor Author

you06 commented Feb 16, 2023

/test mysql-test

Signed-off-by: you06 <[email protected]>
@you06 you06 requested a review from coocood February 16, 2023 09:17
@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Feb 16, 2023
@VelocityLight VelocityLight added cherry-pick-approved Cherry pick PR approved by release team. and removed do-not-merge/cherry-pick-not-approved labels Feb 16, 2023
Copy link
Member

@jackysp jackysp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Feb 17, 2023
@you06
Copy link
Contributor Author

you06 commented Feb 17, 2023

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: 1ab6790

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Feb 17, 2023
@you06
Copy link
Contributor Author

you06 commented Feb 17, 2023

/test unit-test

Signed-off-by: you06 <[email protected]>
@ti-chi-bot ti-chi-bot removed the status/can-merge Indicates a PR has been approved by a committer. label Feb 17, 2023
@qw4990
Copy link
Contributor

qw4990 commented Feb 17, 2023

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: f73452a

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Feb 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherry-pick-approved Cherry pick PR approved by release team. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants